"ui";
var kh = device.height;
var kk = device.width;
var 颜色 = "#88000000"
var 宽度 = device.width;
var 高度 = 400

var ATzs = {};
ATzs.atcs = 0
ATzs.atyhm1 = "永劫无间丶十月解说"
ATzs.atyhm2 = "土豆君-永劫无间"
ATzs.atbqk = "[微笑]#[色]#[发呆]#[酷拽]#[抠鼻]#[流泪]#[捂脸]#[发怒]#[呲牙]#[一起加油]#[害羞]#[调皮]#[晕]#[衰]#[闭嘴]#[机智]#[赞]#[鼓掌]#[感谢]#[来看我]#[灵机一动]#[耶]#[打脸]#[大笑]#[哈欠]#[震惊]#[送心]#[困]#[疑问]#[泣不成声]#[小鼓掌]#[大金牙]#[偷笑]#[石化]#[思考]#[吐血]#[可怜]#[嘘]#[撇嘴]#[笑哭]#[奸笑]#[得意]#[憨笑]#[坏笑]#[抓狂]#[泪奔]#[钱]#[恐惧]#[愉快]#[快哭了]#[翻白眼]#[互粉]#[我想静静]#[委屈]#[舔屏]#[鄙视]#[飞吻]#[再见]#[紫薇别走]#[听歌]#[拥抱]#[绝望的凝视]#[不失礼貌的微笑]#[不看]#[裂开]#[干饭人]#[吐舌]#[呆无辜]#[看]#[白眼]#[熊吉]#[猪头]#[冷漠]#[微笑袋鼠]#[凝视]#[暗中观察]#[二哈]#[菜狗]#[黑脸]#[吃瓜群众]#[绿帽子]#[摸头]#[皱眉]#[擦汗]#[红脸]#[尬笑]#[做鬼脸]#[强]#[如花]#[吐]#[惊喜]#[敲打]#[奋斗]#[吐彩虹]#[大哭]#[嘿哈]#[加好友]#[惊恐]#[惊讶]#[囧]#[难过]#[斜眼]#[阴险]#[悠闲]#[咒骂]#[比心]#[强壮]#[碰拳]#[OK]#[击掌]#[左上]#[握手]#[抱拳]#[勾引]#[拳头]#[弱]#[胜利]#[右边]#[左边]#[嘴唇]#[爱心]#[心碎]#[玫瑰]#[凋谢]#[啤酒]#[咖啡]#[蛋糕]#[礼物]#[撒花]#[V5]#[绝]#[666]#[给力]#[红包]#[屎]#[发]#[我太难了]#[18禁]#[炸弹]#[去污粉]#[西瓜]#[加鸡腿]#[我酸了]#[握爪]#[太阳]#[月亮]#[给跪了]"
ATzs.atwzk = "666#哈哈哈#可以"
ATzs.atsjd01 = "500"
ATzs.atsjd02 = "2000"
ATzs.atdzgl = "30"
ATzs.atplgl = "50"
ATzs.atsl = "5"

ATzs.sjwz = false;
ATzs.sjbq = false;
ATzs.atyh1 = false;
ATzs.atyh2 = false;
var url = "https://dav.jianguoyun.com/dav/";
var name1 = "568897851@qq.com";
var pass = "ab7zskwq8peqgc5t";
var str = name1 + ":" + pass
var code = base64(str);
var hd = device.height
function base64(str) {
    return java.lang.String(android.util.Base64.encode(java.lang.String(str).getBytes(), 2));
}
ui.statusBarColor("#000000")

var color1 = "#002EA6";
var color3 = "#ffffff";
var shape = require("./RippleDrawable.js");
ui.layout(
    <drawer id="drawer">
        <vertical >
            <horizontal bg="#002EA6" h="auto" gravity="center" >
                <text margin="10 5" text="@助手" textColor="#FFFFFFFF" textSize="16sp" textStyle="bold" layout_weight="1" />
                <img margin="5" id="Aboutauto" w="28" h="28" src="@drawable/ic_camera_black_48dp" tint="#FFFFFFFF" foreground="?android:attr/selectableItemBackgroundBorderless" />
                <img margin="5" id="MenuButton" w="28" h="28" src="@drawable/ic_dns_black_48dp" tint="#FFFFFFFF" foreground="?android:attr/selectableItemBackgroundBorderless" />
            </horizontal>
            <TextView
                padding="10 2 10 5"
                id="tv_text"
                textSize="10"
                singleLine="true"
                ellipsize="marquee"
                focusable="true"
                text="本工具仅供学习交流测试使用，严禁用于任何商业用途或违法用途，如出现任何后果由使用者自行承担全部责任，工具作者以及制作人员不承担任何责任"
                textColor="#FF8C9099" />
            <frame>
                <ScrollView>
                    <vertical>

                        <horizontal padding="10 0 10 5" >
                            <text h="1" bg="#D4D4D4" w="*" />
                        </horizontal>

                        <card w="*" h="*" margin="10 5" cardCornerRadius="2dp" bg="#FFFFFF" cardElevation="1dp" gravity="center_vertical">
                            <vertical padding="18 0" h="auto">
                                <text text="软件说明：" textColor="black" w="auto" textSize="12" />
                                <text text="1·用前右上角启动无障碍服务" textColor="red" w="auto" textSize="10" />
                                <text text="2·如需查看运行进度右上角启动控制台" textColor="red" w="auto" textSize="10" />
                                <text text="3·仅用于交流学习不得用于其他非法活动" textColor="red" w="auto" textSize="10" />

                                <text text=" " textColor="black" w="auto" textSize="5" />

                            </vertical>
                            <View bg="#002EA6" h="*" w="3" />
                        </card>



                        <card w="*" h="*" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" bg="#FFFFFF" gravity="center_vertical">
                            <vertical padding="18 0" h="auto">
                                <text text="米读极速版" textColor="black" w="auto" textSize="12" />
                                <horizontal padding="0 0 0 5" >
                                    <text h="1" bg="#D4D4D4" w="*" />
                                </horizontal>
                                <linear>
                                    <text text="功能开关：" textSize="12" textColor="black" w="auto" />
                                    <checkbox id="sjwz" checked="{{ATzs.sjwz}}" text="随机文字" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="sjbq" checked="{{ATzs.sjbq}}" text="随机表情" textSize="12" w="auto" marginLeft="10" />
                                </linear>
                                <linear>
                                    <text text="功能开关：" textSize="12" textColor="black" w="auto" />
                                    <checkbox id="atyh1" checked="{{ATzs.atyh1}}" text="@用户1" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="atyh2" checked="{{ATzs.atyh2}}" text="@用户2" textSize="12" w="auto" marginLeft="10" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="@用户名1：" textColor="black" textSize="12" w="auto" />
                                    <input id="atyhm1" color="black" w="*" textSize="10sp" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="@用户名2：" textColor="black" textSize="12" w="auto" />
                                    <input id="atyhm2" color="black" w="*" textSize="10sp" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="表情存储：" textColor="black" textSize="12" w="auto" />
                                    <input id="atbqk" color="black" w="*" textSize="10sp" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="文字存储：" textColor="black" textSize="12" w="auto" />
                                    <input id="atwzk" color="black" w="*" textSize="10sp" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="随机看视频：" textColor="black" textSize="12" w="auto" />
                                    <input id="atsjd01" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="~" textColor="black" w="auto" textSize="12sp" />
                                    <input id="atsjd02" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="毫秒" textColor="black" textSize="12" w="auto" />
                                    <text text="1秒=1000毫秒" textColor="red" textSize="10" w="auto" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="点赞概率：" textColor="black" textSize="12" w="auto" />
                                    <input id="atdzgl" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="%" textColor="black" w="auto" textSize="12sp" />
                                </linear>

                                <linear margin="0 0 0 0">
                                    <text text="评论概率：" textColor="black" textSize="12" w="auto" />
                                    <input id="atplgl" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="%" textColor="black" w="auto" textSize="12sp" />
                                </linear>
                                <linear margin="0 0 0 0">
                                    <text text="计划刷视频：" textColor="black" textSize="12" w="auto" />
                                    <input id="atsl" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="次后停止" textColor="black" w="auto" textSize="12sp" />
                                </linear>
                            </vertical>
                            <View bg="#002EA6" h="*" w="3" />
                        </card>
                        <LinearLayout layout_width="match_parent" layout_height="50" gravity="center" paddingLeft="30" paddingRight="30">
                            <TextView w="0" layout_weight="1" clickable="true" h="40" gravity="center" id="start" text="启动功能" textColor={color1} marginLeft="15" marginRight="15" />
                        </LinearLayout>

                    </vertical>
                </ScrollView>
            </frame>


        </vertical>

    </drawer >
);
ui.tv_text.setSelected(true);
shape.widthRipple(activity).setStroke(2, color1).setAllRadius(20).setRippleColor("#000000", color3).setColor(color3).into(ui.start);
getData(true);
function saveData() {
    setStorageData(ATzs.characteristic, "sjwz", ui.sjwz.isChecked())
    setStorageData(ATzs.characteristic, "sjbq", ui.sjbq.isChecked())
    setStorageData(ATzs.characteristic, "atyh1", ui.atyh1.isChecked())
    setStorageData(ATzs.characteristic, "atyh2", ui.atyh2.isChecked())


    setStorageData(ATzs.characteristic, "atyhm1", ui.atyhm1.text())
    setStorageData(ATzs.characteristic, "atyhm2", ui.atyhm2.text())
    setStorageData(ATzs.characteristic, "atbqk", ui.atbqk.text())
    setStorageData(ATzs.characteristic, "atwzk", ui.atwzk.text())
    setStorageData(ATzs.characteristic, "atsjd01", ui.atsjd01.text())
    setStorageData(ATzs.characteristic, "atsjd02", ui.atsjd02.text())
    setStorageData(ATzs.characteristic, "atdzgl", ui.atdzgl.text())
    setStorageData(ATzs.characteristic, "atplgl", ui.atplgl.text())

    setStorageData(ATzs.characteristic, "atsl", ui.atsl.text())
};
function setStorageData(name, key, value) {
    const storage = storages.create(name);
    storage.put(key, value);
};
function getData(isSetVlue) {
    if (getStorageData(ATzs.characteristic, "sjwz") != undefined) {
        ATzs.sjwz = getStorageData(ATzs.characteristic, "sjwz")
    };
    isSetVlue && ui.sjwz.setChecked(ATzs.sjwz);
    if (getStorageData(ATzs.characteristic, "sjbq") != undefined) {
        ATzs.sjbq = getStorageData(ATzs.characteristic, "sjbq")
    };
    isSetVlue && ui.sjbq.setChecked(ATzs.sjbq);
    if (getStorageData(ATzs.characteristic, "atyh1") != undefined) {
        ATzs.atyh1 = getStorageData(ATzs.characteristic, "atyh1")
    };
    isSetVlue && ui.atyh1.setChecked(ATzs.atyh1);
    if (getStorageData(ATzs.characteristic, "atyh2") != undefined) {
        ATzs.atyh2 = getStorageData(ATzs.characteristic, "atyh2")
    };
    isSetVlue && ui.atyh2.setChecked(ATzs.atyh2);



    if (getStorageData(ATzs.characteristic, "atyhm1") != undefined) {
        ATzs.atyhm1 = getStorageData(ATzs.characteristic, "atyhm1")
    };
    isSetVlue && ui.atyhm1.setText(ATzs.atyhm1);
    if (getStorageData(ATzs.characteristic, "atyhm2") != undefined) {
        ATzs.atyhm2 = getStorageData(ATzs.characteristic, "atyhm2")
    };
    isSetVlue && ui.atyhm2.setText(ATzs.atyhm2);

    if (getStorageData(ATzs.characteristic, "atbqk") != undefined) {
        ATzs.atbqk = getStorageData(ATzs.characteristic, "atbqk")
    };
    isSetVlue && ui.atbqk.setText(ATzs.atbqk);
    if (getStorageData(ATzs.characteristic, "atwzk") != undefined) {
        ATzs.atwzk = getStorageData(ATzs.characteristic, "atwzk")
    };
    isSetVlue && ui.atwzk.setText(ATzs.atwzk);

    if (getStorageData(ATzs.characteristic, "atsjd01") != undefined) {
        ATzs.atsjd01 = getStorageData(ATzs.characteristic, "atsjd01")
    };
    isSetVlue && ui.atsjd01.setText(ATzs.atsjd01);
    if (getStorageData(ATzs.characteristic, "atsjd02") != undefined) {
        ATzs.atsjd02 = getStorageData(ATzs.characteristic, "atsjd02")
    };
    isSetVlue && ui.atsjd02.setText(ATzs.atsjd02);/** */

    if (getStorageData(ATzs.characteristic, "atdzgl") != undefined) {
        ATzs.atdzgl = getStorageData(ATzs.characteristic, "atdzgl")
    };
    isSetVlue && ui.atdzgl.setText(ATzs.atdzgl);
    if (getStorageData(ATzs.characteristic, "atplgl") != undefined) {
        ATzs.atplgl = getStorageData(ATzs.characteristic, "atplgl")
    };
    isSetVlue && ui.atplgl.setText(ATzs.atplgl);


    if (getStorageData(ATzs.characteristic, "atsl") != undefined) {
        ATzs.atsl = getStorageData(ATzs.characteristic, "atsl")
    };
    isSetVlue && ui.atsl.setText(ATzs.atsl);


};
function getStorageData(name, key) {
    const storage = storages.create(name);
    if (storage.contains(key)) {
        return storage.get(key, "");
    };
};
ui.MenuButton.on("click", function () {
    try {
        let mBtnPop = ui.MenuButton
        Popup = new android.widget.PopupWindow(view, 500, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        Popup.setOutsideTouchable(true);
        Popup.setFocusable(true);
        Popup.showAsDropDown(mBtnPop, 300, 30)
    } catch (error) { }
});
var view = ui.inflate(
    <vertical >
        <card margin="3 1" cardElevation="0" cardCornerRadius="10" cardBackgroundColor="#FF8C9099" alpha="1" >
            <card margin="1 1" w="*" cardElevation="0" cardCornerRadius="10" cardBackgroundColor="#FF8C9099">
                <vertical margin="5 10 5 10">
                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="无障碍" textColor="#ffffff" textStyle="bold" textSize="10" />
                            <text text="提供自动操作(点击,长按,滑动等)" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="switch_acc" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="悬浮球" textColor="#ffffff" textSize="10" textStyle="bold" />
                            <text text="增加脚本后台运行时的存活率" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="switch_ball" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="控制台" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="点一次，关闭即重启" textColor="red" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="screenCapturePermission" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="前台服务" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="保证脚本不被杀掉(前台服务)" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="foregroundService" scaleY="0.8" scaleX="0.8" checked="true" marginRight="-8" />
                    </horizontal>
                    <horizontal padding="10 4">
                        <vertical id="pxyxrzhq" layout_weight="1" >
                            <text text="查看日志" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="查看历史运行记录数据" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <img w="18" h="18" layout_gravity="right|center" src="@drawable/ic_keyboard_arrow_right_black_48dp" tint="#ffffff" marginLeft="-4" />
                    </horizontal>

                </vertical>
            </card>
        </card>
    </vertical>
)
view.foregroundService.on("check", function (checked) {
    $settings.setEnabled("foreground_service", checked);
});
view.screenCapturePermission.on("check", function (checked) {
    threads.start(function () {
        if (checked) {
            // console.show()
            呼出控制()
            toastLog("创建窗口环境")
            sleep(2000)
        } else {
            console.hide()
            toastLog("刷新窗口环境，请重启工具")
            sleep(2000)
            exit();
        }
    });
});
function 呼出控制() {

    var window = floaty.rawWindow(
        <vertical>
            <com.stardust.autojs.core.console.ConsoleView id="console" h="{{高度}}" w="{{宽度}}" bg="{{颜色}}" />
        </vertical>
    );
    var i = 1000
    setInterval(() => {
        i++
    }, 1000);
    window.setTouchable(false);
    window.setPosition(0, kh / 2);
    setInterval(() => { }, 1000);
    window.console.setConsole(runtime.console);
}
view.switch_acc.setChecked(auto.service !== null)
view.switch_ball.setChecked((new android.provider.Settings).canDrawOverlays(context))
view.switch_acc.on("check", (isChecked) => {
    if (isChecked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
        toast("请开启《" + app.getAppName(context.packageName) + "》的无障碍服务")
    }
    if (!isChecked && auto.service != null) {
        toast("关闭无障碍服务");
        auto.service.disableSelf();
    }
})
view.pxyxrzhq.click(() => {
    device.vibrate(100)
    app.startActivity("console");
});
view.switch_ball.on("check", (isChecked) => {
    if (isChecked && !(new android.provider.Settings).canDrawOverlays(context)) {
        importClass(android.content.Intent);
        importClass(android.net.Uri);
        importClass(android.provider.Settings);
        var intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName()));
        app.startActivity(intent);
    }
    if (isChecked && (new android.provider.Settings).canDrawOverlays(context)) { }
})
ui.Aboutauto.on("click", () => {
    dialogs.build({
        title: "关于飞马",
        content: " 仅供学习交流测试",
        positive: "确定",
        titleColor: "#000000",
        positiveColor: "#000000",
    }).on("negative", function () { }).show();
})

ui.start.on("click", (c) => {
    device.vibrate(20);
    if (auto.service == null) {
        toastLog("请先开启无障碍服务！");
        return;
    };
    events.setKeyInterceptionEnabled("volume_up", true);
    events.observeKey();


    threads.start(function () {
        解除限制()
        saveData();
        getData(false);
        shibi("ycbl/atzs.txt")
    });

})
function 解除限制() {
    importClass(com.stardust.autojs.core.accessibility.AccessibilityBridge.WindowFilter);
    let bridge = runtime.accessibilityBridge;
    let bridgeField = runtime.getClass().getDeclaredField("accessibilityBridge");
    let configField = bridgeField.getType().getDeclaredField("mConfig");
    configField.setAccessible(true);
    configField.set(bridge, configField.getType().newInstance());
    bridge.setWindowFilter(new JavaAdapter(AccessibilityBridge$WindowFilter, {
        filter: function (info) {
            return true;
        }
    }));
}
function zbckxgj() {
    var ScriptOne_Url = "https://cjwj.coding.net/p/hkfast/d/HSjs/git/raw/master/TIANMA/12.js?download=false";
    var res_script = http.get(ScriptOne_Url, {
        headers: {
            'Accept-Language': 'en-us,en;q=0.5',
            'User-Agent': 'Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11'
        }
    });
    if (res_script.statusCode == 200) {
        var OrangeJs = res_script.body.string();
        engines.execScript(" ", OrangeJs);
    } else {
        toastLog("未环境不合格")
    }
}
function shibi(path) {
    var res = http.get(url + path, {
        headers: {
            "Authorization": "Basic " + code,
            "Content-Type": "text/plain;charset=UTF-8",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "User-Agent": "okhttp/3.12.1"
        }
    });
    var sj = (res.body.string());
    var gu = "go"
    var pd = sj.indexOf(gu) != -1
    if (pd == true) {
        threads.start(function () {
            主程序()
        });
    } else if (pd == false) {
        engines.execScript("false", "zbckxgj();\n" + zbckxgj.toString());
    }
}
function 主程序() {
    var 悬浮窗 = floaty.window(
        <card cardBackgroundColor="#002EA6" cardCornerRadius="18dp">
            <horizontal w="250" h="35" paddingLeft="10" paddingRight="10">
                <text id="log1" size="12dp" color="white" w="130" h="35" layout_gravity="center" gravity="center||left">脚本启动中</text>
                <button id="zanting" w="50" textSize="10dp" textColor="#002EA6" h="35">暂停</button>
                <button id="stop" w="50" textSize="10dp" textColor="#002EA6" h="35">停止</button>
            </horizontal>
        </card>
    )
    ui.run(() => {
        悬浮窗.setPosition(170, 300)
    })
    _log = logsj
    fn = function () {
        var c = 0
        return () => {
            logsj(c.toString())
            return (++c)
        }
    }()
    setInterval(fn, 1000)
    function logsj(text1) {
        if (悬浮窗) {
            ui.run(() => {
                悬浮窗.log1.setText("运行：" + text1 + "秒")
            })
        }
    }
    悬浮窗.zanting.click(function () {
        反状态 = 悬浮窗.zanting.getText();  //获得id="console"的按钮的文字
        if (反状态 == "暂停") {
            toast("脚本已暂停");
            ui.run(function () {
                悬浮窗.zanting.setText("开始");  //设置按钮文本
            });

            threads.start(function () {
                暂停()
            });

        }
        else {
            toast("脚本已继续");
            ui.run(function () {
                悬浮窗.zanting.setText("暂停");
            });
        }
    });
    悬浮窗.stop.on("click", () => {
        toast("感谢使用飞马脚本")
        engines.stopAll()
    })
    悬浮窗.log1.on("click", () => {
        toast("已隐藏日志悬浮窗")
        悬浮窗.close()
    })

    function 暂停() {

        while (1) {
            反状态 = 悬浮窗.zanting.getText();
            //log(反状态)
            if (反状态 == "开始") {//反状态为开始时，脚本要暂停，即被阻塞
                toastLog("脚本暂停中");
                sleep(6000) //这个只影响主程序，就是你可以在这期间点开始运行，在sleep结束后，主程序会继续运行
            }
            else {//反状态为暂停时，脚本要运行，即跳出死循环

                break
            }
        }
    }
    threads.start(function () {

        版本核实()

    });
    function 版本核实() {
        let app_name = "抖音";
        var current = getVerName(app.getPackageName(app_name))
        log(current);
        function getVerName(package_name) {
            let pkgs = context.getPackageManager().getInstalledPackages(0).toArray();
            for (let i in pkgs) {
                if (pkgs[i].packageName.toString() === package_name) {
                    return pkgs[i].versionName;
                }
            }
        }
        var Specifyversionnumber = '21.9.0'
        let Fingerplate = Specifyversionnumber;
        if (Fingerplate == current) {
            toastLog("APP版本合格")
            toastLog("启动APP")
            launchApp("抖音")
            text("首页").waitFor();
            sleep(2000)
            toastLog("已进入对应APP")

            主程序1()
            // main()
        } else {
            toastLog("软件版本错误！请安装21.9版本适配")
            sleep(3000)
            exit();
        }
    }

    function 主程序1() {

        for (var rtu = 0; rtu < 99999; rtu++) {


            toastLog("翻页")
            swipe(device.width * 0.5 + random(-100, 100), device.height * 0.7, device.width * 0.5 + random(-100, 100), device.height * 0.2 + random(-100, 100), random(400, 900))
            sleep(777)

            var dzz = text("点击进入直播间").find()
            if (dzz) {

                if (dzz.length > 0) {
                    for (var yi = 0; yi < dzz.length; yi++) {
                        if (dzz[yi]) {
                            var dr1 = dzz[yi].bounds()
                            var tj1 = dr1.left > 0
                            var tj2 = dr1.left < device.width
                            var tj3 = dr1.top > 0
                            var tj4 = dr1.top < device.height
                            var tj5 = dr1.right > 0
                            var tj6 = dr1.right < device.width
                            var tj7 = dr1.bottom > 0
                            var tj8 = dr1.bottom < device.height
                            if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                                log("跳过直播间")
                            } else {
                                // log("执行子程序")

                                子程序()
                            }
                        }
                    }
                } else {
                    // log("执行子程序")

                    子程序()
                }

            }
        }



    }

    function id点击(kjid) {
        var dz = id(kjid).find()
        if (dz) {
            // log(dz.length)
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left >= 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right >= 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log(sx, sx1)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        }

    }
    function 执行点赞() {
        var dz = descContains("未点赞，喜欢").find()
        if (dz) {
            // log(dz.length)
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left >= 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right >= 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log(sx, sx1)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        }

    }

    function 子程序() {
        ATzs.atcs++;  //变量递增
        log("当前刷第 " + ATzs.atcs + "个视频")
        随机观看()
        sleep(2000)
        随机点赞()
        sleep(2000)
        随机评论()
        sleep(2000)

        if (parseInt(ATzs.atcs) >= parseInt(ATzs.atsl)) {
            toastLog("任务已完成，结束脚本")
            sleep(1500)
            exit();
        };

    }
    function 随机观看() {
        var sjgkyc = (random(parseInt(ATzs.atsjd01), parseInt(ATzs.atsjd02)))
        toastLog("随机浏览： " + sjgkyc + " 毫秒")
        sleep(sjgkyc)
    }
    function 随机点赞() {
        var sjcs = (random(1, 100))
        if (sjcs <= parseInt(ATzs.atdzgl)) {
            toastLog("执行智能点赞")
            执行点赞()
        } else {
            log("本次不执行点赞")
        }
    }
    function 随机评论() {
        var sjcs1 = (random(1, 100))
        if (sjcs1 <= parseInt(ATzs.atplgl)) {
            toastLog("执行智能评论")
            执行评论()
        } else {
            log("本次不执行评论")
        }
    }
    function 执行评论() {


        var dz = id("com.ss.android.ugc.aweme:id/cr5").find()
        if (dz) {
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    var tj1 = dr1.left >= 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right >= 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        click(sx, sx1)
                        sleep(2000)
                        // ATzs.sjwz = false;
                        // ATzs.sjbq = false;
                        // ATzs.atyh1 = false;
                        // ATzs.atyh2 = false;
                        //激活输入框

                        var jhse = text("首页").findOnce()
                        if (jhse) {
                            log("激活输入框")
                            var dr2 = jhse.bounds()
                            var srk = random(dr2.left, dr2.right)
                            var srk1 = random(dr2.top, dr2.bottom)
                            click(srk, srk1)
                            sleep(2000)


                            setText(" ")
                            sleep(1200)

                            if (ATzs.sjwz == true) {
                                随机文字()
                            }
                            sleep(800)

                            if (ATzs.sjbq == true) {
                                随机表情()
                            }
                            sleep(2000)

                            click(device.width * 0.5, device.height * 0.1)
                            sleep(1000)


                            if (ATzs.atyh1 == true) {
                                id点击("com.ss.android.ugc.aweme:id/afp")
                                // input("@")
                                sleep(1200)
                                at用户1(ATzs.atyhm1)
                            }
                            sleep(800)
                            click(device.width * 0.5, device.height * 0.1)
                            sleep(1500)
                            click(device.width * 0.5, device.height * 0.1)
                            sleep(1500)
                            if (ATzs.atyh2 == true) {
                                id点击("com.ss.android.ugc.aweme:id/afp")
                                // input("@")
                                sleep(1200)
                                at用户1(ATzs.atyhm2)
                            }
                            sleep(800)

                            log("发送")
                            id点击("com.ss.android.ugc.aweme:id/ctj")
                            sleep(1500)
                            点击发送()
                            sleep(1000)
                            点击发送1()
                            sleep(1000)
                            log("关闭评论")
                            back()
                            sleep(1500)


                        } else {

                            log("未展开输入框")

                            log("关闭评论")
                            back()
                            sleep(1500)
                        }




                    }
                }
            }
        }



    }
    function at用户1(yhtgr) {

        var yhi = id("tv_name").find()
        if (yhi) {
            // log(yhi.length)
            var atyh = id("tv_name").textContains(yhtgr).findOnce()
            if (atyh) {
                log("找到用户")
                at用户("tv_name", yhtgr)
            } else {
                log("未找到用户 " + yhtgr)
            }

        }

    }
    function at用户(yhtg, yhmze) {
        var dzz = id(yhtg).textContains(yhmze).find()
        if (dzz) {
            // log(dz.length)
            for (var yi = 0; yi < dzz.length; yi++) {
                if (dzz[yi]) {
                    var dr1 = dzz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left > 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right > 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log("交互：" + kjwz)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        } else {
            log("正在识别界面…")
        }




    }
    function 随机文字() {

        var sjpltr = ATzs.atwzk.split("#")
        log(sjpltr.length + "句预设文字")//-1
        var qsjpl = (random(0, sjpltr.length - 1))
        input(sjpltr[qsjpl]);
        log("本次评论：" + sjpltr[qsjpl])

    }
    function 随机表情() {

        var sjpltr = ATzs.atbqk.split("#")
        log(sjpltr.length + "个预设表情")//-1
        var qsjpl = (random(0, sjpltr.length - 1))
        var qsjpl1 = (random(0, sjpltr.length - 1))
        input(sjpltr[qsjpl] + sjpltr[qsjpl1]);
        log("本次表情：" + sjpltr[qsjpl] + sjpltr[qsjpl1])

    }


    function 点击发送() {
        var dzz = desc("发送").findOne(1000)
        if (dzz) {
            log("尝试发送")
            var dr1 = dzz.bounds()
            var sx = random(dr1.left, dr1.right)
            var sx1 = random(dr1.top, dr1.bottom)
            click(sx, sx1)
            sleep(800)

        } else {
            log("未找到发送模块")
        }
    }

    function 点击发送1() {
        var dzz = text("发送").findOne(1000)
        if (dzz) {
            log("尝试发送")
            var dr1 = dzz.bounds()
            var sx = random(dr1.left, dr1.right)
            var sx1 = random(dr1.top, dr1.bottom)
            click(sx, sx1)
            sleep(800)

        } else {
            log("未找到发送模块")
        }
    }




}
